/**
 * 
 */
package org.bitmap.mm;

import java.util.List;

import org.bitmap.mm.util.ImageCaches;
import org.bitmap.mm.util.LoveBitmapManager;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author Administrator
 * 
 */
public final class ImageAdapter extends ArrayAdapter<String> {

	LoveBitmapManager bm;
	private LayoutInflater mInflater;

	public ImageAdapter(Context context, List<String> urls, LoveBitmapManager BM) {
		super(context, 0, urls);
		bm = BM;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder cache  = null;
		if (view == null) {
			view = mInflater.inflate(R.layout.image_item, parent, false);
			cache = new ViewHolder();
			cache.image = (ImageView) view.findViewById(R.id.image);
			cache. name = (TextView) view.findViewById(R.id.name);
			view.setTag(cache);
		}
		else{
			cache = (ViewHolder) view.getTag();
		}
		String url = getItem(position);
		cache.name.setText("index= "+position);
		bm.loveLoadImageAsTasks(url, cache.image,-1,Bitmap.Config.RGB_565);
		
		return view;
	}
	
	class ViewHolder{
		ImageView image;
		TextView name;
	}

}
